package com.xpresso.utils.filesystem;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import com.xpresso.utils.exceptions.XpressoException;

public class FileManager {

	public static void copyFiles(String strPath, String dstPath)throws XpressoException {
		File src = new File(strPath);
		File dest = new File(dstPath);
	
		if (src.isDirectory()){
			dest.mkdirs();
			String list[] = src.list();
			for (int i = 0; i < list.length; i++) {
				String dest1 = dest.getAbsolutePath() + "\\" + list[i];
				String src1 = src.getAbsolutePath() + "\\" + list[i];
				copyFiles(src1 , dest1);
			}
		} else {
			try {
				FileInputStream fin = new FileInputStream(src);
				FileOutputStream fout = new FileOutputStream (dest);
				int c;
				while ((c = fin.read()) >= 0){
					fout.write(c);
				}
				fin.close();
				fout.close();				
			} catch (IOException e) {
				throw new XpressoException("An error occurred copying files.", e);
			}
		}		
	}

	
}
